﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PX.ImageFile;

public partial class ShowContent : System.Web.UI.Page
{
	private ImageFileComponent clsUploadFileComp = new ImageFileComponent();

	private int nFileID;		// 要现实的文件ID

	protected void Page_Load(object sender, EventArgs e)
	{
		ImageFile clsShowUploadFile = new ImageFile();
		byte[] bFileContent;
		string[] strArrShow;
		Boolean bShow;			// 上传的文件是否直接显示，true直接显示

		strArrShow = new string[2];
		bShow = false;

		strArrShow[0] = "text/html";
		strArrShow[1] = "message/rfc822";

		nFileID = Convert.ToInt32(Request.QueryString["FileID"].ToString());

		//clsShowUploadFile = clsUploadFileComp.GetOne(nFileID);
		clsUploadFileComp.GetOneByID(nFileID, clsShowUploadFile);

		bFileContent = clsShowUploadFile.Content;
		Response.Clear();
		Response.AddHeader("Content-Type", clsShowUploadFile.Type);


		for (int i = 0; i < strArrShow.Length; i++)
		{
			if (clsShowUploadFile.Type == strArrShow[i])
			{
				bShow = true;
				break;
			}
		}
		if (bShow)
		{
			Response.AddHeader("Content-Disposition", "inline;");
		}
		else
		{
			HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + CommonFunction.UTF_FileName(clsShowUploadFile.Name) + "\";");
		}
		//Response.AddHeader("Content-Disposition", "inline;");

		Response.BinaryWrite(bFileContent);
		Response.Flush();
		Response.End();
	}
}
